﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SharePointCustomizer
{
    public partial class Find : Form
    {
        public RichTextBox RichTextBoxControl;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_richTextControl"></param>
        public Find(RichTextBox _richTextControl)
        {
            InitializeComponent();

            RichTextBoxControl = _richTextControl;
        }
        /// <summary>
        /// btnFindNext Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFindNext_Click(object sender, EventArgs e)
        {
            if (checkMatchCase.Checked)
            {
                RichTextBoxControl.SelectionStart += txtFindWhat.Text.Length;
                if (RichTextBoxControl.Find(txtFindWhat.Text, RichTextBoxControl.SelectionStart, RichTextBoxFinds.MatchCase) == -1)
                {
                    RichTextBoxControl.SelectionStart = 0;
                    
                    MessageBox.Show("No more matching words. ");
                }
            }
            else
            {
                RichTextBoxControl.SelectionStart += txtFindWhat.Text.Length;
                if (RichTextBoxControl.Find(txtFindWhat.Text, RichTextBoxControl.SelectionStart, RichTextBoxFinds.WholeWord) == -1)
                {
                    RichTextBoxControl.SelectionStart = 0;
                    MessageBox.Show("No more matching words. ");
                }
            }
            RichTextBoxControl.Focus();
        }
        /// <summary>
        /// btnCancel Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        /// <summary>
        /// txtFindWhat PreviewKeyDown
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtFindWhat_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnFindNext.PerformClick();
            }
        }
    }
}
